package ru.spbau.bytecode.geom;

import java.awt.Point;


public class Line {
	
	public final int a;
	public final int b;
	public final int c;
	public static final double eps = 1e-9;
	
	public Line(Segment s) {
		a = s.a.y - s.b.y;
		b = s.b.x - s.a.x;
		c = -(a * s.a.x + b * s.a.y);
	}
	
	public boolean intersects(Line l) {
		return a * l.b - l.a * b != 0;
	}
	
	public Point getIntersection(Line l) {
		if (!intersects(l)) {
			return null;
		}
		
		int d = a * l.b - l.a * b;
		int x = -(int)Math.round((c * l.b - l.c * b) * 1.0 / d);
		int y = -(int)Math.round((a * l.c - l.a * c) * 1.0 / d);
		return new Point(x, y);
	}
}